﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.IO.Ports;
using TCA_User.Common;
using TCA_User.Tab_Class;

namespace TCA_User
{
    public partial class Bill_List
    {
        private const bool AUTO_RESIZE = true;
        private const bool NO_AUTO_RESIZE = false;
        

        private System.Windows.Forms.TabPage Taxi_Manage_Tab;
        private Gridview_Grp Card_Table_Form;
        private TextBox_Lbl card_name;

        private ComboBox_Lbl Taxi_Provider_Name;
        private DataTable TaxiManage_Taxi_Tbl;

        private ComboBox_Lbl Card_Owner;
        private DataTable Card_Owner_Tbl;

        private RichText_Lbl Note_RichText;
        private Button Taxi_Add_BT; // = new Button();

        public bool Init_Taxi_Manage_Tab()
        {
            PosSize possize = new PosSize(); ;
            string tab_name = "Taxi_Card";
             //= new TextBox_Lbl("Card ID", TextBox_Type.TEXT, PosSize possize);
            Taxi_Manage_Tab = new System.Windows.Forms.TabPage();
            Taxi_Manage_Tab.Text = tab_name;
            Taxi_Manage_Tab.SuspendLayout();
            Taxi_Manage_Tab.Location = new System.Drawing.Point(4, 22);
            Taxi_Manage_Tab.Size = new System.Drawing.Size(900, 390);
            Taxi_Manage_Tab.Padding = new System.Windows.Forms.Padding(3);
            Taxi_Manage_Tab.TabIndex = 1;
            Taxi_Manage_Tab.UseVisualStyleBackColor = true;
            Taxi_Manage_Tab.ResumeLayout(true);
            Taxi_Manage_Tab.PerformLayout();

            this.MainTabControl.Controls.Add(this.Taxi_Manage_Tab);

            // Init Card Table
            possize.pos_x = 6;
            possize.pos_y = 6;
            possize.width = Taxi_Manage_Tab.Size.Width - 400;
            possize.height = Taxi_Manage_Tab.Size.Height - 10;
            Card_Table_Form = new Gridview_Grp(Taxi_Manage_Tab, "Card Table", possize, AUTO_RESIZE,
                                                TCA_Database_Conn, @"SELECT * FROM dbo.Cards_TBL", AnchorType.RIGHT);

            possize.pos_x = Taxi_Manage_Tab.Size.Width - 380;
            possize.pos_y = 36;
            // TaxiManage_Taxi_Tbl = Get_Taxi_Provider_Name_Tbl();
            TaxiManage_Taxi_Tbl = Taxi_TBL_Form.Data_dtb;
            Taxi_Provider_Name = new ComboBox_Lbl(Taxi_Manage_Tab, "Taxi Provider", possize,
                            TaxiManage_Taxi_Tbl, "Taxi_Provider_Name", "Taxi_Provider_Name", AnchorType.RIGHT);
            
            possize.pos_x = Taxi_Manage_Tab.Size.Width - 380;
            possize.pos_y = 66;
            card_name = new TextBox_Lbl(Taxi_Manage_Tab, "Card Name", TextBox_Type.TEXT, possize, AnchorType.RIGHT);

            possize.pos_x = Taxi_Manage_Tab.Size.Width - 380;
            possize.pos_y = 96;
            Card_Owner_Tbl = Account_TBL_Form.Data_dtb;
            Card_Owner = new ComboBox_Lbl(Taxi_Manage_Tab, "Card Owner", possize,
                            Card_Owner_Tbl, "UserName", "UserName", AnchorType.RIGHT);

            possize.pos_x = Taxi_Manage_Tab.Size.Width - 380;
            possize.pos_y = 186;
            possize.width = 300;
            possize.height = 180;
            Note_RichText = new RichText_Lbl(Taxi_Manage_Tab, "Note", TextBox_Type.TEXT, possize, AnchorType.RIGHT);

            Taxi_Add_BT = new Button();
            Taxi_Manage_Tab.Controls.Add(Taxi_Add_BT);
            Taxi_Add_BT.Location = new System.Drawing.Point(Taxi_Manage_Tab.Size.Width - 380, 400);
            // Add_BT.Size = new System.Drawing.Size(200, 20);
            Taxi_Add_BT.Text = "Add";
            Taxi_Add_BT.Anchor = ((System.Windows.Forms.AnchorStyles)((
                                System.Windows.Forms.AnchorStyles.Top)
                                | System.Windows.Forms.AnchorStyles.Right));
            Taxi_Add_BT.Click += new System.EventHandler(Taxi_AddBT_BT_Click_event);
            return true;
        }

        private void Taxi_AddBT_BT_Click_event(object sender, EventArgs e)
        {
            string value = "";
            string sql_cmd = @"INSERT INTO [TCA_DATABASE].[dbo].[Cards_TBL] ([Taxi_Provider_Name]
                                  ,[Card_Provider_Name]
                                  ,[Card_Owner]
                                  ,[Card_Note])
                                    VALUES ";
            value += "'" + Taxi_Provider_Name.My_Combo.Text.Trim() + "', ";
            value += "'" + card_name.My_TextBox.Text.Trim() + "', ";
            value += "'" + Card_Owner.My_Combo.Text.Trim() + "', ";
            value += "'" + Note_RichText.My_RichText.Text.Trim() + "'";
            sql_cmd = sql_cmd + "( " + value + ")";

            if (Update_Data_Info(TCA_Database_Conn, sql_cmd) == false)
            {
                MessageBox.Show("Insert Fail", "Error");
            }
            else
            {
                Card_Table_Form.Refresh_Form();
            }
        }
    }
}